<template>
	<view class="address">
		<view class="list" v-if="addressList.length">
			<view class="itemadd" v-for="item in addressList" :key="item._id" @click="editAdd(item._id)" >
				<!-- left -->
				<view class="left">
					<text class="iconfont icondizhi"></text>
				</view>
				<!-- middle -->
				<view class="middle">
					<view class="info">
						<view class="name">
							{{ item.name }}
						</view>
						<view class="phone">
							{{ item.phone }}
						</view>
					</view>
					<view class="address_txt">
						<text class="default" v-if="item.defaultAdd == 1">默认</text>
						<text class="addinfo">
							{{ item.province }} {{ item.city }} {{ item.country }} {{ item.address }}
						</text>
					</view>
				</view>
				<!-- right  -->
				<view class="right">
					编辑
				</view>
			</view>
		</view>
		
		<!-- 如果没有地址 -->
		<view class="noadd" v-else>
			<view class="icon">
				<text class="iconfont icondizhi" ></text>
			</view>
			<view class="txtinfo">
				暂无地址,请添加!
			</view>
		</view>
		
		<view class="addbtn">
			<button type="primary" @click="addUserAddress">添加地址</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList: []
			}
		},
		computed: {
			token() {
				return this.$store.state.token;
			}
		},
		onShow() {
			this.getAddressList()
		},
		methods: {
			// 获取地址列表
			async getAddressList() {
				// this.addressList = []
				let res = await this.$Request("/admin/getUserAddress", "", this.token)
				console.log(res);
				let code = res.data.code
				if(code == 200) {
					let inx = ""
					let item = {}
					this.addressList = res.data.data.addressList
					
				}
			},
			
			// 去添加地址
			addUserAddress() {
				uni.navigateTo({
					url:`/pages/addressadd/addressadd?type=add`
				})
			},
			
			// 编辑地址
			editAdd( id ) {
				// console.log(id);
				uni.navigateTo({
					url: `/pages/addressadd/addressadd?type=${id}`
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.address {
		width: 100%;
		padding: 10rpx 20rpx;
		box-sizing: border-box;
		padding-bottom: 120rpx;
		.list {
			width: 100%;
			box-sizing: border-box;
			.itemadd{
				width: 100%;
				box-sizing: border-box;
				display: flex;
				padding: 20rpx;
				align-items: center;
				border-radius: 60rpx;
				box-shadow: 0 0 5rpx #aaa;
				margin: 20rpx 0;
				.left {
					width: 100rpx;
					color: green;
					text-align: center;
				}
				.middle {
					flex: 1;
					padding-right: 30rpx;
					.info {
						width: 100%;
						display: flex;
						align-items: center;
						height: 60rpx;
						line-height: 60rpx;
						.name {
							font-size: 30rpx;
						}
						.phone {
							font-size: 20rpx;
							margin-left: 30rpx;
							color: #999;
						}
					}
					.address_txt {
						font-size: 20rpx;
						width: 100%;
					
						.default {
							color: #fff;
							width: 80rpx;
							
							padding: 0 10rpx;
							text-align: center;
							background-color: red;
							margin-right: 30rpx;
							border-radius: 30rpx;
						}
						.addinfo {
							flex: 1;
						}
					}
				}
				.right {
					width: 100rpx;
					font-size: 24rpx;
					text-align: center;
					color: #aaa;
					border-left: 1px solid #aaa;
				}
			}
			
		}
		
		.noadd {
			width: 100%;
			padding-top: 20%;
			text-align: center;
			color: #aaa;
			.icon {
				text {
					font-size: 200rpx;
				}
			}
		}
		.addbtn {
			width: 100%;
			text-align: center;
			position: fixed;
			left: 0;
			bottom: 50rpx;
			button {
				border-radius: 60rpx;
				width: 500rpx;
				font-size: 30rpx;
			}
		}
	}
</style>
